package NC101_压缩字符串1;

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param param string字符串
     * @return string字符串
     */
    public String compressString (String param) {
        // write code here
        if (param.length() <= 1){
            return param;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(param.charAt(0));
        for (int i = 1; i < param.length();){
            if (param.charAt(i) != param.charAt(i - 1)){
                sb.append(param.charAt(i));
                i++;
                continue;
            }
            int count = 1;
            while (i < param.length() && param.charAt(i) == param.charAt(i - 1)){
                count++;
                i++;
            }
            sb.append(count);
        }
        return sb.toString();
    }
}